package com.gimi.cloud.bbp.app.consumer.service.alipay.impl;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.gimi.cloud.bbp.app.consumer.feign.alipay.AliPayNotifyFeignService;
import com.gimi.cloud.bbp.app.consumer.service.alipay.AliPayNotifyService;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;

/**
 * 支付宝异步通知服务
 * @author 李林峰
 * @version 1.0
 * @Description
 * @create 2018年2月2日
 */
@Service
public class AliPayNotifyServiceImpl implements AliPayNotifyService {
	
	private static final Logger log = LoggerFactory.getLogger(AliPayNotifyServiceImpl.class);

	@Autowired AliPayNotifyFeignService feignService;

	@Override
	public String alipayNotify(HttpServletRequest request) {
		try {
			Map<String, String[]> requestParams = request.getParameterMap();
			log.info("支付宝异步通知参数："+JSON.toJSONString(requestParams));
			String alipayNotify = feignService.alipayNotify(requestParams);
			Response result = JSON.parseObject(alipayNotify,Response.class);
			if ("0000".equals(result.getRes_code())) {
				return "success";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

}